package com.aaa.controller.jl;

import com.aaa.pojo.jl.ResltBean;
import com.aaa.pojo.jl.QusetionSas;
import com.aaa.service.jl.QuestionSasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

@RestController
public class QuestionSasController {
    @Autowired
    private QuestionSasService questionSasService;
    ResltBean resltBean = new ResltBean();


    @RequestMapping("/quSas")
    public ResltBean findAll(String  page, String limit){
        int count = questionSasService.findCount();
        List<QusetionSas> all = questionSasService.findAll(page,limit);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(count);
        resltBean.setData(all);
        return resltBean;
}
   @RequestMapping("/insertSas")
    public ResltBean questionSasInter(QusetionSas qusetionSas){


       qusetionSas.setCreatetime(new Date());
        int insert = questionSasService.insert(qusetionSas);
       resltBean.setCode(0);
       resltBean.setMsg("");
       resltBean.setCount(insert);
       resltBean.setData(qusetionSas);
        return resltBean;
    }
    @RequestMapping("/updateSas")
    public ResltBean questionSasUpdate(QusetionSas qusetionSas ){
        qusetionSas.setUpdatetime(new Date());
        int update = questionSasService.update(qusetionSas);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(update);
        resltBean.setData(qusetionSas);
        return  resltBean;
    }
    @RequestMapping("/deleteSas")
    public ResltBean questionSasDelete(String idList){
        int delete = questionSasService.deleteById(idList);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(delete);
        resltBean.setData(idList);
        return  resltBean;
    }

    @RequestMapping("/fyzztQuestion")
    public ResltBean fyzzQuestion(String question){
        int count = questionSasService.findCount();
        //1.调用service方法
        List<QusetionSas> qusetionSas = questionSasService.fuzzyQuestion(question);
        //2.实例化一个ModelAndView对象
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(count);
        resltBean.setData(qusetionSas);
        return resltBean;
    }
    @RequestMapping("/fyzztCreateBy")
    public ResltBean fyzzCreateBy(String createBy){
        int count = questionSasService.findCount();
        //1.调用service方法
        List<QusetionSas> qusetionSas = questionSasService.fuzzyCreateBy(createBy);
        //2.实例化一个ModelAndView对象
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(count);
        resltBean.setData(qusetionSas);
        return resltBean;
    }
    @RequestMapping("/fuzzyQuestionAndCreatBy")
    public ResltBean fuzzyQuestionAndCreatBy(String question,String createBy,String page,String limit){
        int count = questionSasService.queryCountLike(question, createBy);
        //1.调用service方法
        List<QusetionSas> qusetionSas = questionSasService.fuzzyQuestionAndCreatBy(question, createBy,page,limit);
        //2.实例化一个ModelAndView对象
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(count);
        resltBean.setData(qusetionSas);
        return resltBean;
    }

    @RequestMapping("deleteIdList")
    public ResltBean deleteByIds(@RequestParam("idList") List<String> idList) {
        int i = questionSasService.deleteList(idList);
        resltBean.setCode(0);
        resltBean.setMsg("");
        return  resltBean;
    }

    @RequestMapping({"toShowQuestionSas.do"})
    public ModelAndView toShowQuestionFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("showQuestionSas");
        return modelAndView;
    }
}
